package com.mlc.core.serviceImpl;

import com.mlc.data.entity.Details;
import com.mlc.data.dao.DetailsDao;
import com.mlc.core.service.DetailsService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * @author FireWang
 * @date 2022/03/14 02:46:46
 */
@Service
@AllArgsConstructor
@Transactional
public class DetailsServiceImpl implements DetailsService {
    private DetailsDao detailsDao;

    @Override
    public List<Details> getAll() {
        return detailsDao.findAll();
    }

    @Override
    public Details getById(Integer id) {
        Optional<Details> details = detailsDao.findById(id);
        return details.get();
    }

    @Override
    public void insert(Details details) {
        details.setCreateTime(new Date());
        detailsDao.save(details);
    }

    @Override
    public void update(Details details) {
        details.setModifyTime(new Date());
        detailsDao.save(details);
    }

    @Override
    public void deleteById(Integer id) {
        detailsDao.deleteById(id);
    }
}